(function (lib, config) {
    var loadFunc = function () {
        var wordAry = config.words.split('|'), bgcolorAry = config.bgcolor.split('|'), textcolorAry = config.textcolor.split('|'), weblinkAry = config.weblink.split('|');
        wordAry[0] = wordAry[0] || '张医生';
        wordAry[1] = wordAry[1] || '向你发来了一条消息';
        textcolorAry[0] = textcolorAry[0] || '#fff';
        textcolorAry[1] = textcolorAry[1] || '#f6f6f6';
        bgcolorAry[0] = bgcolorAry[0] || '#292929';
        weblinkAry[0] = weblinkAry[0] || '';
        /*TODO 方法*/
        var sHTML = [
            '<style type="text/css">',/*left:0; top: 0;*/
            '.topTips { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; position: fixed; '+lib.util.getPosStyle(config)+' width: 100%; z-index: 100000;-webkit-perspective: 600px; perspective: 600px;}',
            '.tipsInner {font-family: "Microsoft YaHei"; -webkit-box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5); background: {{bgcolor}};-webkit-transform-origin: 0px 0px; transform-origin: 0px 0px; -webkit-transform: rotateX(90deg); transform: rotateX(90deg); opacity: 0; }',
            '.tipsInner a { text-decoration:none;display: block; position: relative; padding-left: 50px;}',
            '.tipsInner em {display:block;position: absolute; left: 8px; top: 50%; margin-top: -20px; width: 36px; height: auto; padding-right: 5px; background: {{bgcolor}}; }',
            '.tipsInner em:after{content:"";display:block;width:10px;height:10px;background:#f00;border-radius:100%;position:absolute;top:-2px;right:0;}',
            '.tipsInner img {display:block;width:36px;}',
            '.tipsInner dl { margin:0; padding: 10px 5px 14px;}',
            '.tipsInner dt { font-weight: bold;line-height:1em;font-size:14px;font-family: "Microsoft YaHei";}',
            '.tipsInner dt span{ font-weight: bold;line-height:1em;font-size:16px;font-family: "Microsoft YaHei"; color:#fff;padding-right: 10px;}',
            '.tipsInner p{width:50px;height:4px;border-radius:15px;background:#5e5e5e;position: absolute;top: 50px;left: 50%;margin:0 0 0 -25px;}',
            '.tipsInner dd { margin:0; line-height: 1.2em;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;font-size:14px; font-family: "Microsoft YaHei";color:#fff; padding-top:3px;}',
            '.showTip { visibility:visible; }',
            '.showTip .tipsInner { -webkit-transform-origin: 0px 0px; transform-origin: 0px 0px; -webkit-transform: rotateX(0deg); transform: rotateX(0deg); opacity: 1; }',
            '.hideTip { visibility:hidden; }',
            '.hideTip .tipsInner { -webkit-transform-origin: 0px 100%; transform-origin: 0px 100%; -webkit-transform: rotateX(-90deg); transform: rotateX(-90deg); opacity: 0; }',
            '</style>',
            '<div class="topTips hideTip" id="toptips">',
            '   <div class="tipsInner">',
            '   <a href="javascript:window.open(\'{{weblink}}\',\'_blank\');" class="JS-SWT-LINK" target="_blank">',
            '         <p></p>',
            '         <em><img src="http://nkm.6660333.cn/images/wx.png"></em>',
            '         <dl>',
            '           <dt style="color:{{textcolor1}}">{{str1}}</dt>',
            '           <dd style="color:{{textcolor2}}">{{str2}}</dd>',
            '         </dl>',
            '       </a>',
            '   </div>',
            '</div>'
        ].join('\r\n');
        sHTML = lib.util.resolveTemplate(sHTML, "str1", wordAry[0], "str2", wordAry[1], "textcolor1", textcolorAry[0],'textcolor2',textcolorAry[1], "bgcolor", bgcolorAry[0], "weblink", config.weblink);
        var o = document.createElement('div');
        o.innerHTML = sHTML;
        while (o.firstElementChild) {
            document.body.appendChild(o.firstElementChild);
        };
        T = { hasClass: function (d, a) { var c = d.className.split(/\s+/); for (var b = 0; b < c.length; b++) { if (c[b] == a) { return true } } return false }, addClass: function (b, a) { if (!this.hasClass(b, a)) { b.className += " " + a } }, removeClass: function (d, a) { if (this.hasClass(d, a)) { var c = d.className.split(/\s+/); for (var b = 0; b < c.length; b++) { if (c[b] == a) { delete c[b] } } d.className = c.join(" ") } } };
        function Toptips(options) {
            this.init(options);
        };
        Toptips.prototype = {
            constructor: Toptips,
            init: function (options) {
                this.item = options.item;
                this.itemInner = options.item.children[0];
                this.loop = typeof options.loop == "undefined" ? true : options.loop;
                this.showTime = typeof options.showTime == "undefined" ? 5000 : options.showTime;
                this.hideTime = typeof options.hideTime == "undefined" ? 5000 : options.hideTime;
                this.showTimer = null;
                this.hideTimer = null;
                this.preTimer = null;
                this.item.style.WebkitTransition = this.item.style.transition = this.itemInner.style.WebkitTransition = this.itemInner.style.transition = "0.5s";
                var me = this;
                var initTimer = setTimeout(function () {
                    me.showTip();
                }, 1000);
            },

            showTip: function () {
                var me = this;
                T.addClass(me.item, "showTip");
                T.removeClass(me.item, "hideTip");

                clearTimeout(me.hideTimer);
                me.showTimer = setTimeout(function () {
                    me.hideTip();
                }, me.showTime);

            },
            hideTip: function () {
                var me = this;
                T.removeClass(me.item, "showTip");
                T.addClass(me.item, "hideTip");
                me.item.style.visibility = me.itemInner.style.visibility = "hidden";

                if (me.loop) {
                    clearTimeout(me.showTimer);

                    me.preTimer = setTimeout(function () {
                        me.item.style.visibility = me.itemInner.style.visibility = "visible";
                    }, me.hideTime - 100);

                    me.hideTimer = setTimeout(function () {
                        me.showTip();
                    }, me.hideTime);

                }
            },

        };
        setTimeout(function () {
            var toptip = document.getElementById("toptips");
            new Toptips({
                item: toptip,
                loop: true,
                showTime: +config.eachtime ? config.eachtime * 1000 : undefined,
                hideTime: +config.relapsetime ? config.relapsetime * 1000 : undefined
            });
        }, config.firsttime * 1000);
    };
    lib.load(loadFunc);/*执行代码*/
})('{{lib}}', '{{config}}');